home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC18AccessPriv / UEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-25  |  3.9 KB  |  146 lines  |  [04] ASCII Text (0x0000)

  1. /***********************************************************************
  2. *
  3. * AccessPriv uEvent.c
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1989-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements the
  12. * main event loop used by the AccessPriv program.
  13. *
  14. ***********************************************************************/
  15.  
  16. #include <types.h>
  17. #include <locator.h>
  18. #include <quickdraw.h>
  19. #include <event.h>
  20. #include <menu.h>
  21. #include <window.h>
  22. #include <misctool.h>
  23. #include <resources.h>
  24.  
  25. #include "ap.h"
  26.  
  27. extern char             test[80];
  28. extern WmTaskRec        event;
  29. extern unsigned int     quitFlag, suppressErrors;
  30. extern int              userisowner;
  31.  
  32. static GrafPortPtr  lastWindow; /* This private global used in checkFrontW()
  33.                                 ** to prevent extra work when the windows
  34.                                 ** have not changed.  It is initialized
  35.                                 ** at the beginning of mainEvent().
  36.                                 */
  37.  
  38. extern void NewPrivs();
  39.  
  40. /**********************************************************************
  41. *
  42. * doControls
  43. *
  44. * This procedure is called when an inControl message is returned
  45. * by TaskMaster.
  46. *
  47. * When this routine gets control, the ID of the control that was
  48. * hit is in TaskDATA4.  The control handle is in TaskData2 and
  49. * the part code is in taskData 3.
  50. *
  51. **********************************************************************/
  52. void    doControls()
  53. {
  54.     unsigned int    theID;
  55.  
  56.     theID = event.wmTaskData4;
  57.  
  58.     if (theID == SaveBut) {
  59.         if (userisowner) NewPrivs(); /* does user have selected privs? */
  60.         }
  61.  
  62.     if (theID == UndoBut) CurrentPrivs();
  63.     if (theID == ViewAnotherBut) {
  64.         ChooseFolder();
  65.         CurrentPrivs();
  66.     }
  67. }
  68.  
  69. /*********************************************************************
  70. *
  71. * checkFrontW
  72. *
  73. * This routine checks the front window to see if any changes need
  74. * to be made to the menu items.
  75. *
  76. * We do this so that the edit items are only active when a desk
  77. * accessory is active.
  78. *
  79. *********************************************************************/
  80. void    checkFrontW()
  81. {
  82.     GrafPortPtr     theWindow;
  83.  
  84.     theWindow = FrontWindow();
  85.         /* Get the front window into local storage.*/
  86.     
  87.     if (theWindow == lastWindow) return;
  88.         /* If the lastWindow is this window, we are all set. */
  89.     
  90.     /* If there are no windows, everything should be disabled */
  91.     if (!theWindow) {
  92.         SetMenuFlag(0x0080, EditMenuID);
  93.         DrawMenuBar();
  94.     }
  95.     else {
  96.         /* Otherwise we look at the window and see what to do. */
  97.         if (GetSysWFlag(theWindow)) {
  98.             SetMenuFlag (0xFF7F, EditMenuID);     /* Set up for da windows. */
  99.             DrawMenuBar();
  100.         }
  101.         else {
  102.             SetMenuFlag (0x0080, EditMenuID);     /* Set up for our windows. */
  103.             DrawMenuBar();
  104.         }
  105.     }
  106.  
  107.     lastWindow = theWindow;     /* Remember this for next time. */
  108. }
  109.  
  110. /*************************************************************************
  111. *
  112. * mainEvent
  113. *
  114. * This is the main part of the program.  The program cycles in this
  115. * loop until the user choose select.
  116. *
  117. *************************************************************************/
  118. void    mainEvent()
  119. {
  120.     unsigned int    code;
  121.  
  122.     event.wmTaskMask = 0x001FFFFF;  /* Allow TaskMaster to do everything.   */
  123.     quitFlag         = 0;           /* Done flag will be set by Quit item.  */
  124.     lastWindow       = NULL;        /* Init this for checkFrontW().         */
  125.  
  126.     for (;;) {
  127.         checkFrontW();
  128.         suppressErrors = 0;
  129.         code = TaskMaster(0xFFFF, &event);
  130.  
  131.         switch(code) {
  132.             case wInGoAway:
  133.                 doCloseTop();
  134.                 break;
  135.             case wInSpecial:
  136.             case wInMenuBar:
  137.                 doMenu();
  138.                 break;
  139.             case wInControl:
  140.                 doControls();
  141.                 break;
  142.         }
  143.         if (quitFlag) break;
  144.     }
  145. }
  146.